package cn.cs.controller;

import cn.cs.client.CsFactoryClient;
import cn.cs.client.CsPartsClient;
import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.common.EmptyUtils;
import cn.cs.pojo.CsFactory;
import cn.cs.pojo.CsParts;
import cn.cs.service.AgentOrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "/agentOrder")
public class AgentOrderController {

    @Resource
    private AgentOrderService agentOrderService;

    @Resource
    private CsPartsClient partsClient;

    @Resource
    private CsFactoryClient factoryClient;

    /**
     * 分页查询 订货单列表
     *
     * @param pageNumber
     * @param pageSize
     * @return
     * @throws Exception TODO 添加搜索
     */
    @RequestMapping(value = "/csPlatform/getAgentOrderByPage")
    public Dto getAgentOrderByPage(Integer pageNumber, Integer pageSize, String factoryId, String factory_name, String parts_name, String name, String person, String phone) throws Exception {
        Map<String, Object> param = new HashMap<>();
        param.put("factory_id", factoryId);
        param.put("factory_name", factory_name);
        param.put("parts_name", parts_name);
        param.put("name", name);
        param.put("person", person);
        param.put("phone", phone);
        if(EmptyUtils.isNotEmpty(factoryId) || EmptyUtils.isNotEmpty(factory_name) || EmptyUtils.isNotEmpty(parts_name)){
            List<CsParts> list = partsClient.getCsPartsByFactoryId(factoryId, factory_name, parts_name);
            if(EmptyUtils.isEmpty(list) || list.size() <= 0){
                CsParts parts = new CsParts();
                parts.setId("000");
                list.add(parts);
            }
            param.put("list", list);
        }
        return DtoUtil.returnSuccess("获取成功", agentOrderService.queryAgentOrderPageByMap(param, pageNumber, pageSize));
    }





}
